feat: add attribute-based controller routing and inspector UI, plus basePath fixes#8
feat: add attribute-based controller routing and inspector UI, plus basePath fixes#8
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new attribute-driven controller routing layer for Glaze’s dev server, including an inspector UI page, and introduces basePath-aware handling so dev UI assets/routes work when the site is served under a subpath.
Changes:
- Introduces
#[Route]/#[RoutePrefix]attributes, route discovery/matching (ControllerRouter+MatchedRoute), and controller dispatch/rendering (ControllerMiddleware,ControllerViewRenderer). - Adds a development inspector controller + Sugar template and ships dev UI assets served from
/_glaze/assets/...viaCoreAssetMiddleware. - Wires the dev router + container to enable these features in non-static (dev) mode, with accompanying unit tests.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/Http/Routing/ControllerViewRendererTest.php | Adds coverage for controller-view template resolution/rendering. |
| tests/Unit/Http/Routing/ControllerRouterTest.php | Adds coverage for attribute-based route discovery and matching. |
| tests/Unit/Http/Middleware/CoreAssetMiddlewareTest.php | Adds coverage for core asset serving and basePath stripping behavior. |
| tests/Unit/Http/Middleware/ControllerMiddlewareTest.php | Adds coverage for controller dispatch and argument injection behavior. |
| tests/Fixture/Http/ArticleController.php | Fixture controller to validate unprefixed routes. |
| tests/Fixture/Http/AdminController.php | Fixture controller to validate prefixed routes + method constraints. |
| src/Http/Routing/MatchedRoute.php | Introduces a value object for matched controller routes. |
| src/Http/Routing/ControllerViewRenderer.php | Adds Sugar-based HTML rendering for array-return controller actions. |
| src/Http/Routing/ControllerRouter.php | Implements attribute-based controller discovery + request matching. |
| src/Http/Middleware/CoreAssetMiddleware.php | Serves package dev UI assets under /_glaze/assets/*, basePath-aware. |
| src/Http/Middleware/ControllerMiddleware.php | Dispatches matched controller actions and resolves action arguments. |
| src/Http/Controller/InspectorController.php | Adds dev-only inspector endpoint(s) under /_glaze/*. |
| src/Http/Attribute/RoutePrefix.php | Defines a controller-level route prefix attribute. |
| src/Http/Attribute/Route.php | Defines an action-level route attribute with method normalization. |
| src/Application.php | Registers ControllerMiddleware in the container. |
| resources/vite.config.js | Adds a Vite build config for core dev UI assets. |
| resources/templates/inspector/routes.sugar.php | Adds inspector “routes” page template. |
| resources/package.json | Adds frontend tooling config for building core dev UI assets. |
| resources/assets/css/dev.css | Adds dev UI styling for the inspector pages. |
| bin/dev-router.php | Wires core asset + controller middleware into the dev server pipeline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
ece1476 to
e97717f
Compare
…spector hrefs, test improvements
e97717f to
8fff4db
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds an attribute-driven MVC-style routing layer (controller discovery, route matching, dispatch, and view rendering) plus a development-time “Inspector” routes page, and introduces basePath-aware handling so controller/asset routes work when the site is hosted under a subpath.
Changes:
- Introduces
#[Route]/#[RoutePrefix]attributes,ControllerRouterdiscovery+matching,MatchedRoute, and controller dispatch middleware with argument auto-wiring. - Adds a dev-only Inspector controller + Sugar template UI and a core asset middleware to serve
/_glaze/assets/*. - Adds unit tests covering routing, middleware behavior, view rendering, and basePath handling.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/Http/Routing/ControllerViewRendererTest.php | Tests template existence checks and Sugar rendering response behavior. |
| tests/Unit/Http/Routing/ControllerRouterTest.php | Tests attribute-based route discovery and matching semantics. |
| tests/Unit/Http/Middleware/CoreAssetMiddlewareTest.php | Tests core asset serving and basePath stripping behavior. |
| tests/Unit/Http/Middleware/ControllerMiddlewareTest.php | Tests controller dispatch, DI/path param injection, and basePath routing behavior. |
| tests/Fixture/Http/ArticleController.php | Fixture controller for unprefixed route matching tests. |
| tests/Fixture/Http/AdminController.php | Fixture controller for prefixed routes + multi-method handling tests. |
| src/Http/Routing/MatchedRoute.php | Adds a value object describing a matched controller route. |
| src/Http/Routing/ControllerViewRenderer.php | Adds Sugar-based renderer for array-return controller actions. |
| src/Http/Routing/ControllerRouter.php | Adds controller file discovery and request matching for #[Route] attributes. |
| src/Http/Middleware/CoreAssetMiddleware.php | Adds middleware to serve package assets under /_glaze/assets/* with basePath stripping. |
| src/Http/Middleware/ControllerMiddleware.php | Adds controller dispatch middleware with basePath-aware matching and argument resolution/coercion. |
| src/Http/Controller/InspectorController.php | Adds Inspector controller action for listing discovered content routes. |
| src/Http/Attribute/RoutePrefix.php | Adds class-level route prefix attribute. |
| src/Http/Attribute/Route.php | Adds repeatable method-level route attribute with HTTP method normalization. |
| src/Application.php | Registers ControllerMiddleware as a shared container service. |
| resources/vite.config.js | Adds Vite config for building core dev-UI assets. |
| resources/templates/inspector/routes.sugar.php | Adds Inspector “routes” UI template. |
| resources/package.json | Adds JS tooling dependencies/scripts for core dev-UI assets build. |
| resources/assets/css/dev.css | Adds Inspector/dev-UI stylesheet. |
| bin/dev-router.php | Wires core asset + controller middleware into the dev request pipeline (non-static mode). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
- Pass original request (not basePath-stripped copy) to action resolveArguments so controller actions see the real incoming URI path - Switch InspectorController to LocalizedContentDiscovery so i18n-enabled projects see all language-prefixed pages in the routes inspector - Prefix CSS stylesheet href and nav link with $basePath in inspector template so subpath deployments resolve inspector assets/navigation correctly - HTML-escape all ContentPage values (urlPath, title, type) in template to prevent XSS from project frontmatter content - Update CoreAssetMiddleware docblock to accurately describe PHP-emitted basePath prefix (not Sugar static-attribute rewriting)
There was a problem hiding this comment.
Pull request overview
This PR adds an attribute-based MVC controller routing system and a built-in development “inspector” routes page, along with basePath-aware fixes so dev inspector links and core assets work correctly when served from a subpath.
Changes:
- Introduces controller routing primitives (Route/RoutePrefix attributes, ControllerRouter matching, MatchedRoute, and ControllerViewRenderer rendering).
- Adds dev-only inspector controller + template, and serves dev UI assets via CoreAssetMiddleware.
- Wires the new middleware into the dev router and expands unit test coverage for routing, middleware dispatch/injection, and basePath behavior.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/Http/Routing/ControllerViewRendererTest.php | Unit tests for template existence checks and HTML rendering. |
| tests/Unit/Http/Routing/ControllerRouterTest.php | Unit tests for attribute discovery/matching and parameter extraction. |
| tests/Unit/Http/Middleware/CoreAssetMiddlewareTest.php | Unit tests for core asset serving and basePath stripping behavior. |
| tests/Unit/Http/Middleware/ControllerMiddlewareTest.php | Unit tests for dispatch, injection, basePath miss forwarding, and scalar coercion. |
| tests/Fixture/Http/ArticleController.php | Fixture controller for unprefixed route discovery/matching. |
| tests/Fixture/Http/AdminController.php | Fixture controller for prefixed routes, multi-method routes, and Response returns. |
| src/Http/Routing/MatchedRoute.php | Value object carrying matched controller/action + params and view naming info. |
| src/Http/Routing/ControllerViewRenderer.php | Sugar-based view renderer for array-returning controller actions. |
| src/Http/Routing/ControllerRouter.php | Route discovery via reflection/attributes and request matching. |
| src/Http/Middleware/CoreAssetMiddleware.php | Serves package dev UI assets under /_glaze/assets, basePath-aware. |
| src/Http/Middleware/ControllerMiddleware.php | Dispatch middleware: basePath-aware match, DI argument resolution, rendering. |
| src/Http/Controller/InspectorController.php | Dev-only inspector controller exposing /_glaze/routes. |
| src/Http/Attribute/RoutePrefix.php | Class-level attribute for controller route prefixes. |
| src/Http/Attribute/Route.php | Method-level repeatable route attribute with HTTP method normalization. |
| src/Application.php | Registers ControllerMiddleware in the DI container. |
| resources/vite.config.js | Adds Vite config for building dev UI assets. |
| resources/templates/inspector/routes.sugar.php | Inspector routes page template (links + table UI). |
| resources/package.json | Adds JS build tooling deps/scripts for dev UI assets. |
| resources/assets/css/dev.css | Adds stylesheet for inspector/dev UI. |
| bin/dev-router.php | Wires CoreAssetMiddleware + ControllerMiddleware into dev-mode request pipeline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
This PR introduces a new MVC-style controller routing flow and a built-in inspector routes page for development, then follows up with basePath compatibility fixes so inspector routes and core assets resolve correctly when the site is served under a subpath.
What changed
Why